package org.example.struct.array2;

/**
 * @author liyishan
 * @date 2024/5/16 13:36
 * @apiNote
 */

public class Test01953NumberOfWeeks {
    public long numberOfWeeks(int[] milestones) {
        int longest = milestones[0];
        long rest = 0;
        for(int count : milestones){
            longest = Math.max(longest, count);
            rest += count;
        }
        rest -= longest;
        if (longest > rest + 1) {
            // 此时无法完成所耗时最长的工作
            return rest * 2 + 1;
        } else {
            // 此时可以完成所有工作
            return longest + rest;
        }
    }
}
